//
//  CZTabBar.swift
//  git
//
//  Created by 徐 鹏超 on 16/4/8.
//  Copyright © 2016年 徐 鹏飞. All rights reserved.
//

import UIKit

class CZTabBar: UITabBar {
    
    


    override init(frame:CGRect){
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
    
        addSubview(composeButton)
    
    }
    
    override func layoutSubviews() {
        //
        super.layoutSubviews()
        
        let width = bounds.width/5.0
        let height = bounds.height
        var index = 0
        
        for subview in subviews{
            
            print("----------")
            
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!){
                print("这个类找到了")
            
                subview.frame = CGRectMake(CGFloat(index) * width, 0, width, height)
                
                index++
            
                if index == 2{
                    index++
                    composeButton.frame = CGRectMake(2 * width, 0, width, height)
                }
            
            
        }
        
        
        
    }
    
    
    
    
    
    
}
    
    
    lazy var composeButton:UIButton = {
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        return button
    }()
    
}